﻿using System;

/*Write a program that finds the most frequent number in an array. Example:
	{4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3}  4 (5 times)
*/

    class FrequentNumbers
    {
        static void Main()
        {
            int[] array = new int[] { 4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3 };
            int curCount = 0;
            int maxCount = 0;
            int mostFreqNumber = 0;

            for (int i = 0; i < array.Length; i++)
            {
                curCount = 0;
                for (int j = i; j < array.Length; j++)
                {
                    if (array[i] == array[j])
                    {
                        curCount++;
                    }

                    if (curCount > maxCount)
                    {
                        maxCount = curCount;
                        mostFreqNumber = array[i];

                    }
                }
                
            }
            Console.WriteLine("Found number {0} in {1} positions", mostFreqNumber, maxCount );
        }
    }

